<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>商品列表 - 潮玩商城</title>
    <link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@500&display=swap" rel="stylesheet">
<style>
        body {
                      background-color: #0d0d0d;
            color: #ff66c4;
            font-family: 'Segoe UI', sans-serif;
            margin: 0;
            padding: 20px;
        }

        h2 {
            color: #ff66c4;
            text-shadow: 0 0 10px #ff00aa;
            margin-bottom: 20px;
        }

        .navbar {
            padding: 15px;
            background: #111;
            border-bottom: 2px solid #ff66c4;
            margin-bottom: 20px;
            font-family: 'Orbitron', sans-serif;
        }

        .navbar a {
            color: #ff66c4;
            margin-right: 20px;
            text-decoration: none;
        }

        .navbar a:hover {
            color: #ff00aa;
            text-shadow: 0 0 5px #ff00aa;
        }

        .search-bar, .filter-bar {
            margin-bottom: 15px;
        }

        input[type="text"], select {
            background: #1a1a1a;
            border: 1px solid #ff66c4;
            color: #ff66c4;
            padding: 5px;
        }

        input[type="submit"] {
            background-color: #ff66c4;
            color: #000;
            border: none;
            padding: 6px 12px;
            cursor: pointer;
            font-weight: bold;
        }

        input[type="submit"]:hover {
            background-color: #ff00aa;
            box-shadow: 0 0 10px #ff00aa;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            background: #1a1a1a;
            box-shadow: 0 0 10px #ff00aa;
        }

        th, td {
            border: 1px solid #ff66c4;
            padding: 10px;
            text-align: center;
        }

        th {
            background-color: #111;
        }

        a.action-link {
            color: #ff66c4;
            text-decoration: none;
        }

        a.action-link:hover {
            color: #ff00aa;
            text-shadow: 0 0 5px #ff00aa;
        }

        img {
            border-radius: 8px;
            box-shadow: 0 0 10px #ff00aa;
        }

        @keyframes glow-in {
            from {
                opacity: 0;
                transform: translate(-50%, -10%);
            }
            to {
                opacity: 1;
                transform: translate(-50%, 0%);
            }
        }

        .login-alert a {
            color: #ff00aa;
            text-decoration: underline;
        }
    </style>
</head>
<body>

<c:if test="${sessionScope.loginUser == null}">
    <div class="login-alert" id="loginAlert">
        ⚠️ 请先 <a href="${pageContext.request.contextPath}/login.jsp">登录</a> 后再继续浏览商品！
    </div>
</c:if>

<div class="navbar">
    <c:choose>
        <c:when test="${sessionScope.loginUser != null}">
            欢迎您，${sessionScope.loginUser.uname}
            <a href="${pageContext.request.contextPath}/goods/frontList">商品首页</a>
            <a href="${pageContext.request.contextPath}/cart/list">购物车</a>
            <a href="${pageContext.request.contextPath}/order/myOrders">我的订单</a>
            <a href="${pageContext.request.contextPath}/user/logout" style="color: #ff6b6b;">退出登录</a>
        </c:when>
        <c:otherwise>
            <a href="${pageContext.request.contextPath}/login.jsp">登录</a>
            <a href="${pageContext.request.contextPath}/register.jsp">注册</a>
        </c:otherwise>
    </c:choose>
</div>

<form class="search-bar" action="${pageContext.request.contextPath}/goods/search" method="get">
    关键词：<input type="text" name="keyword" placeholder="请输入商品名" />
    <input type="submit" value="搜索" />
</form>

<form class="filter-bar" action="${pageContext.request.contextPath}/goods/listByCategory" method="get">
    分类：
    <select name="cid" onchange="this.form.submit()">
        <option value="">全部</option>
        <c:forEach var="cat" items="${categoryList}">
            <option value="${cat.cid}" ${param.cid == cat.cid ? "selected" : ""}>${cat.title}</option>
        </c:forEach>
    </select>
</form>

<table>
    <tr>
        <th>图片</th>
        <th>名称</th>
        <th>价格</th>
        <th>操作</th>
    </tr>
    <c:forEach var="g" items="${goodsList}">
        <tr>
            <td><img src="${g.coverUrl}" width="80" height="80"></td>
            <td><a class="action-link" href="${pageContext.request.contextPath}/goods/detail/${g.gid}">${g.name}</a></td>
            <td>${g.price}</td>
            <td><a class="action-link" href="${pageContext.request.contextPath}/cart/add/${g.gid}">加入购物车</a></td>
        </tr>
    </c:forEach>
</table>

<script>
    window.onload = function () {
        const alertBox = document.getElementById('loginAlert');
        if (alertBox) {
            alertBox.style.display = 'block';
        }
    }
</script>

</body>
</html>